YAHOO.namespace("gosearch.go");
// define several class used in one go board

(function(){
    var Dom = YAHOO.util.Dom,
    Event = YAHOO.util.Event,
    Sel = YAHOO.util.Selector;

    var intersection_width = "25px"

    /**
     * define a go board class
     * @constructor
     */
    YAHOO.gosearch.go.GoBoard = function(){
        this.className = "default-goboard";
        this.container = document.createElement("div"),
        this.intersection_array= [];
        this.init();
    };

    /**
     * define some prototype method for GoBoard Class
     */
    YAHOO.gosearch.go.GoBoard.prototype ={
        /**
         * render the goBoard
         * @return an element represented the goBoard
         */
        render:function(){
            var el = this.container;
            el.className = this.className; 
            return el;
        },
        init: function(){
            //let's assume the left and top intersection's index is i=1,j=1
            for(var i=1;i<=19;i++){
                for(var j=1;j<=19;j++){
                    var intersection = new YAHOO.gosearch.go.Intersection(i,j,"");
                    this.intersection_array.push(intersection);
                    this.container.appendChild(intersection.render());
                }
            }

        }
        

    };



    /**
     * define a intersection
     */

    YAHOO.gosearch.go.Intersection =function(x,y,color){
        this.pos_x = x;// int
        this.pos_y = y;// int
        this.color = color;//color only can be assigned by one value in ["",'white','black'].
        
        this.el = document.createElement("div");
        this.className = "intersection";
        this.init();
    };
    YAHOO.gosearch.go.Intersection.prototype ={
        init: function(){
            var el =  this.el;
            Dom.addClass(el,this.className);
            Dom.setStyle(el, "width",intersection_width);
            Dom.setStyle(el, "height",intersection_width);
            Dom.setStyle(el, "float","left");
            if(this.pos_x == 1){
                Dom.addClass(el,"top-line");
            }
            if(this.pos_x == 19){
                Dom.addClass(el,"bottom-line");
            }
            if(this.pos_y == 1){
                Dom.addClass(el,"left-line");
            }
            if(this.pos_y == 19){
                Dom.addClass(el,"right-line");
            }
            if((this.pos_x == 4 || this.pos_x == 10 || this.pos_x == 16) &&
                (this.pos_y == 4 || this.pos_y == 10 || this.pos_y == 16)){
                Dom.addClass(el,"dot");
            }
        },
        /**
         * put one stone on a intersection.
         */
        add: function(color){
            this.color = color;
            var xy = Dom.getXY(this);
            
        },
        remove: function(){

        },

        render: function(){            
            return this.el;
        }
    }

    /**
     * define a chesspiece
     */

    YAHOO.gosearch.go.ChessPiece =function(){
        this.color = ""
        this.pos = null;
    };


})();
